from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select

if __name__ == '__main__':
    sum = int(input("请输入目录数量："))
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    wd = webdriver.Chrome(options=chrome_options)  # options=chrome_options
    wd.maximize_window()
    wd.implicitly_wait(10)
    wd.get("******")
    wd.find_element_by_id('account').send_keys("***")
    #
    wd.find_element_by_id('password').send_keys("****")
    wd.find_element_by_xpath("//*[@id='sub_btn']/span").click()
    wd.find_element_by_xpath("//*[@id='top_menu']/ul/li[2]/a").click()  # 目录管理//*[@id="nav-accordion"]/li/ul/li[1]/ul/li[2]/a
    wd.find_element_by_xpath("//*[@id='nav-accordion']/li/ul/li[1]/a").click()
    wd.find_element_by_xpath("//*[@id='nav-accordion']/li/ul/li[1]/ul/li[2]/a").click()  # 目录管理
    wd.switch_to.frame("pageIFrame")
    Select(wd.find_element_by_xpath("//*[@id='cata_status']")).select_by_value("1")
    Select(wd.find_element_by_xpath("//*[@id='list-table_length']/label/select")).select_by_value("150")

    i = 0
    while i < sum:
        sleep(1.5)
        try:
            wd.find_element_by_link_text("撤回").click()
            element = wd.find_element_by_xpath("(//button[@type='button'])[19]")
            element.click()
        except Exception as e:
            print(e)
            wd.quit()
            break
        i += 1
        print("已撤回第" + str(i) + "个")
    wd.quit()
